<?php
/**
 * 消息中心
 * 订单未支付提醒
 *
 * by abc.com 多用户商城
 *
 *
 */

//by abc.com
//use Shopnc\Tpl;

defined('InShopNC') or exit('Access Invalid!');
class order_remindControl{
    
    public function __construct(){
        register_shutdown_function(array($this,"shutdown"));
    }
    /**
     * 订单未支付提醒
     * 大概下单四个小时执行一次
     * 12个小时执行一次
     */
    public function indexOp(){
    //查询未支付订单
        $model_order=Model('order');
        $model_message_center=Model('message_center');
        $condition['order_state']=10;
        $condition['team_id']=0;
        $order_list=$model_order->getBasicOrderList($condition);  
        foreach ($order_list as $key => $val){
            $msg['remark']=$val['order_sn'];
            $msg_info=$model_message_center->getOneMsg($msg);
            $model_member=Model('member');
            $member_info=$model_member->getMemberInfoByID($val['buyer_id']);
            if($member_info['member_truename']!=null && !empty($member_info['member_truename'])){
                $member_name=$member_info['member_truename'];
            }else{
                $member_name=substr_replace($val['buyer_name'],"****",3,4);
            }
            //3-6小时
            $data=array();
            if(((TIMESTAMP-$val['add_time'])>10800) && ((TIMESTAMP-$val['add_time'])<21600)){
                if($msg_info == null || empty($msg_info)){
                    $data['msg_content']="亲爱的".$member_name."，您的（订单号：".$val['order_sn']."）还未支付";
                    $data['msg_type']=3;
                    $data['msg_receive_id']=$val['buyer_id'];
                    $data['msg_receive_name']=$val['buyer_name'];
                    $data['msg_time']=TIMESTAMP;
                    $data['msg_state']=0;
                    $data['remark']=$val['order_sn'];

                    $result=$model_message_center->saveMsg($data);
                }
            }else if(((TIMESTAMP-$val['add_time'])>39600) && ((TIMESTAMP-$val['add_time'])<4680)){
                if($msg_info != null || !empty($msg_info)){
                    $condition_up['msg_id']=$msg_info['msg_id'];
                    $data_up['msg_state']=0;
                    /* $data['msg_content']="亲爱的".$member_name."，您的订单（订单号：".$val['order_sn']."）还未支付";
                    $data['msg_type']=1;
                    $data['msg_receive_id']=$val['buyer_id'];
                    $data['msg_receive_name']=$val['buyer_name'];
                    $data['msg_time']=TIMESTAMP; */
                    //$data['remark']=$val['order_sn'];
                    $result=$model_message_center->updateMsg($condition_up,$data_up);
                }
            }
            
        }
    }
    
  
}
    